#include "define.h"
#include "appglobaldata.h"
#include "structdefine.h"

UINT16 TM1_usCount = 0;
UINT16 TM1_msCount = 0;
INT_FLAG TM2_INT_FLAG;


//code UINT16 MUSIC_FREQ_LIST[8] = {256, 288, 320, 341, 384, 426, 480, 512};
//code UINT16 MUSIC_FREQ_LIST[8] = {64, 72, 80, 85, 96, 106, 120, 128};
code UINT16 MUSIC_FREQ_LIST[8] = {391, 347, 313, 293, 260, 235, 208, 195};

uint16_t  PWM = 0;			

volatile uint8_t Phase = 0;		//current phase

uint16_t MinRpmPulse = 0;		
bit gNotFullThro = 1;

unsigned char code cBEMF_FILTER[64]= { 0x00,0x02,0x04,0x06,0x08,10,12,14,16,18,20,22,24,26,28,30,
                                        32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,
                                        0x00,0x02,0x04,0x06,0x08,10,12,14,16,18,0x01,22,0x01,26,28,30,
                                        32,34,36,38,0x01,42,44,46,0x01,0x01,0x01,54,56,58,60,62
                                      };
// general purpose variables
unsigned int adc_result;
// commutation parameters
signed char comm_state;
unsigned int comm_time;
bit comm_done,comm_dir;
unsigned int pwm_demand;
unsigned char bemf_filter;
// COMMUTATION variables
unsigned int comm_time,comm_time_max,comm_timer;
signed int phase_delay_counter;
unsigned int phase_delay;
unsigned int phase_delay_filter = COMM_TIME_MAX*8;
bit zc_detected;
bit rotor_locked;
bit CommutateDone;

bit synchronous;
char CompBlankCNT = 0;
PPMCAP	gThrottle; 
SYSINFO gSysInfo;

void InitGlobalData()
{
	SystemState = Stop;
	CommutateState = Block;
	CommutateDone = 1;
	/******/
    comm_dir=0; // spin direction control
    comm_time_max = COMM_TIME_MAX; // initialise maximum commutation time.    
    pwm_demand = 100; // configure CCP module for PWM
    comm_state = 1; // ready to start commutating at state 1
	/******/

}

